import org.junit.Test;

import javax.management.MBeanServerConnection;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
import java.io.IOException;

public class RMIConnect {

    @Test
    public void testRMI() throws IOException {
        String jmxUrl = "service:jmx:rmi:///jndi/rmi://localhost:8999/jmxrmi";
        JMXServiceURL jmxServiceURL = new JMXServiceURL(jmxUrl);
        JMXConnector jmxc = JMXConnectorFactory.connect(jmxServiceURL);
        MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
        for(String domain: mbsc.getDomains()){
            System.out.println(domain);
        }

    }
}
